package com.dmp

import org.apache.spark.{SparkConf, SparkContext}

/**
  * ClassName:ProCityRptV3
  * Package:com.dmp
  * Desciption:
  *
  * @date:2019 /8/23 12:31
  * @author:17611219021 @sina.cn
  */
object ProCityRptV3 {
  def main(args: Array[String]): Unit = {
    if(args.length !=2){
      println(
        """
          |com.dmp.fileToParquet
          |参数：
          | inputpath
          | outputPath
        """.stripMargin)
      sys.exit()
    }
    val conf: SparkConf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.setMaster("local[*]")
    //指定keyo序列化器与snappy格式，默认是gzip格式
    conf.set("spark.serializer","org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.parquet.compression.codec","snappy")
    val sc: SparkContext = new SparkContext(conf)
    val Array(inputpath,outputPath)= args

    sc.textFile(inputpath).map(_.split(",",-1)).filter(_.length >=2)
      .map(arr=>
        ((arr(0),arr(1)),1)
    ).reduceByKey(_+_).saveAsTextFile(outputPath)
    sc.stop()
  }

}
